﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


namespace CSCV.Group8.BlogRollWebPart.VWP
{
    public partial class VWPUserControl : UserControl, Interface.IBRView
    {
        #region field

        private Presenter.BRPresenter presenter;
        #endregion

        #region prop
        public System.Collections.Generic.List<Model.BRPost> ListPost
        {
            set
            {               
                this.rptBlog.DataSource = null;               
                this.rptBlog.DataSource = value;
                this.rptBlog.DataBind();
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region method

        public void AttachPresenter(Presenter.BRPresenter presenter)
        {
            if (presenter == null)
                throw new ArgumentNullException("presenter may not be null");

            this.presenter = presenter;
        }

        protected void btnaddComment_Click(object sender, EventArgs e)
        {
            if (presenter == null)
                return;
            else
            {
                presenter.AddComment(hidTitle.Text, hidComment.InnerHtml, int.Parse(hidPostId.Text), hidUrl.Text);


            }
        }

        protected void timUpdate_Tick(object sender, EventArgs e)
        {
            if (presenter != null)
                presenter.InitView();
        }
        #endregion
    }
}
